<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt"%>
<!DOCTYPE html>
<html>
<head>
<title>addnews</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/indexSecond.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/achievement.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/font-awesome.min.css" />

<!--[if IE 7]>
  <link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/font-awesome-ie7.min.css" />
<![endif]-->

<!-- page specific plugin styles -->

<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/jquery-ui-1.10.3.full.min.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/datepicker.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/ui.jqgrid.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/chosen.css" />

<!-- fonts -->

<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/family_open_sans.css" />

<!-- ace styles -->

<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/ace.min.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/assets/css/ace-skins.min.css" />

<!-- inline styles related to this page -->

<!-- ace settings handler -->

<script src="<%=request.getContextPath()%>/assets/js/ace-extra.min.js"></script>

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

<!--[if lt IE 9]>
<script src="<%=request.getContextPath()%>/assets/js/html5shiv.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container-fluid"  style="position:relative;height:60px;">
	<nav class="navbar  navbar-fixed-top" style="position:absolute;" role="navigation" id="head">
		<div class="container">
	        <div class="navbar-header">
	            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
	                <span class="sr-only">Toggle navigation</span>
	                <span class="icon-bar"></span>
	                <span class="icon-bar"></span>
	                <span class="icon-bar"></span>
	            </button>
	        </div>
	        <div class="navbar-collapse collapse" id="navbar">
	        	
	        	<ul class="nav navbar-nav">
					<li style="border-bottom: 3px solid #fff;"><a href="<%=request.getContextPath()%>/index.do">首页</a></li>
					<li><a href="<%=request.getContextPath()%>/xqq.do">心情墙</a></li>
					<li><a href="<%=request.getContextPath()%>/xdjm.do">兄弟姐妹</a></li>
					<li><a href="<%=request.getContextPath()%>/jqhd.do">近期活动</a></li>
					<li><a href="<%=request.getContextPath()%>/yqlj.do">友情链接</a></li>
				</ul>
				<c:choose>
				<c:when test="${change=='0'}">
					<form action="" class="navbar-form navbar-right">
						<a data-toggle="modal" data-target="#myModal" class="btn btn-primary" href="">登录</a>
	                    <a class="btn btn-primary signup" href="">注册</a>
					</form>
				</c:when>
				<c:when test="${change=='1'}">
					<div class="after-login navbar-right">
						<div  class="col-sm-12 col-xs-12">
							<p>您好,用户:${member.membername}</p>
						</div>
						<div  class="modify col-sm-12 col-xs-12">
							<a data-toggle="modal" data-target="#changePsdModal" href="#">修改密码</a>
							<a data-toggle="modal" data-target="#changeMsgModal" href="#">修改信息</a>
							<a href="<%=request.getContextPath()%>/outlogin.do">注销</a>
						</div>
					</div>
				</c:when>
			 <c:when test="${change=='2'}">
					<div class="after-login navbar-right">
						<div  class="col-sm-12 col-xs-12">
							<p>您好,管理员:${member.membername}</p>
						</div>
						<div  class="modify col-sm-12 col-xs-12">
							<a data-toggle="modal" data-target="#changePsdModal" href="#">修改密码</a>
							<a data-toggle="modal" data-target="#changeMsgModal" href="#">修改信息</a>
							<a href="<%=request.getContextPath()%>/outlogin.do">注销</a>
						</div>
					</div>
				</c:when>
				</c:choose>
	        </div>
		</div>
	</nav>
</div>
<div class="container">
	<div class="col-xs-12 col-sm-12">
		<table id="grid-table"></table>
		<div id="grid-pager"></div>
	</div><!-- /.col -->
</div>
${errorInfo }
${returnInfo}
${returninfo}
</body>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-2.1.4.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/achievement.js"></script>
<!-- jqGrid special  -->
<script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/grid.locale-en.js"></script>
<!-- jqGrid special end -->
<script type="text/javascript">

	jQuery(function($) {
		var grid_selector = "#grid-table";
		var pager_selector = "#grid-pager";
	
		jQuery(grid_selector).jqGrid({
			//direction: "rtl",
			url:"<%=request.getContextPath()%>/admin/getallNews.do",
			datatype : "json",
			mtype: 'post',
			height: 300,
			colNames:['','标题', '创建人', '新闻时间','查看'],
			colModel:[
				{name:'newid',index:'newid',width:40,hidden:true,key:true},
				{name:'title',index:'title', width:80,editable: true,editoptions:{size:"20",maxlength:"30"}},
				{name:'creater',index:'creater', width:60, sorttype:"date", editable: true ,datefmt:true},
				{name:'newstime',index:'newstime', width:70, editable: true,editoptions:{size:"20",maxlength:"30"}},
				{name:'newid',index:'newid',align:"center", width:50, sortable:false,editable:false,
                    formatter: function (value, grid, rows, state) {   
                		var val=value;
                        return "<a class='jqLoad' onclick=loadin(\"<%=request.getContextPath()%>/getdetailofnews.do?newid="+value+"\") href=\"<%=request.getContextPath()%>/getdetailofnews.do?newid="+value+"\" style=\"color:#f60\">查看详情</a>";  
                    },
                },
			],
			viewrecords : true,
			rowNum:10,
			rowList:[10,20,30],
			rownumbers:true,
			pager : pager_selector,
			altRows: true,
			//toppager: true,
			
			multiselect: true,
			//multikey: "ctrlKey",
	        multiboxonly: true,
			/* 当服务器返回响应时执行 */
			loadComplete : function() {
				var table = this;
				setTimeout(function(){
					styleCheckbox(table);
					
					updateActionIcons(table);
					updatePagerIcons(table);
					enableTooltips(table);
				}, 0);
			},
			editurl: "<%=request.getContextPath()%>/admin/delNews.do",
			caption: "添加新闻",
	
	
			autowidth: true
	
		});
		//enable search/filter toolbar
		//jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})
	
		//switch element when editing inline
		function aceSwitch( cellvalue, options, cell ) {
			setTimeout(function(){
				$(cell) .find('input[type=checkbox]')
						.wrap('<label class="inline" />')
					.addClass('ace ace-switch ace-switch-5')
					.after('<span class="lbl"></span>');
			}, 0);
		}
		//enable datepicker
		function pickDate( cellvalue, options, cell ) {
			setTimeout(function(){
				$(cell) .find('input[type=text]')
						.datepicker({format:'yyyy-mm-dd' , autoclose:true}); 
			}, 0);
		}
		//navButtons
		jQuery(grid_selector).jqGrid('navGrid',pager_selector,
			{ 	//navbar options
				edit:false,
				add: false,
				del: true,
				delicon : 'icon-trash red',
				deltitle : '删除',
				deltext : '删除',
				refresh: true,
				refreshicon : 'icon-refresh green',
				refreshtitle : '刷新',
				view: true,
				viewicon : 'icon-zoom-in grey',
				viewtitle : '查看',
				viewtext : '查看',
				search : false,
				alerttext : '请选择一行'
			},
			{
				//edit record form
				//closeAfterEdit: true,
				recreateForm: true,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_edit_form(form);
				}
			},
			{
				//new record form
				closeAfterAdd: true,
				recreateForm: function(){
					
				},
				viewPagerButtons: false,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_edit_form(form);
				}
			},
			{
				//delete record form
				recreateForm: true,
				beforeShowForm : function(e) {
					var form = $(e[0]);
					if(form.data('styled')) return false;
					
					form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
					style_delete_form(form);
					
					form.data('styled', true);
				},
				onClick : function(e) {
					alert(1);
				}
			},
			{
				//search form
				recreateForm: true,
				afterShowSearch: function(e){
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
					style_search_form(form);
				},
				afterRedraw: function(){
					style_search_filters($(this));
				}
				,
				multipleSearch: true,
				/**
				multipleGroup:true,
				showQuery: true
				*/
			},
			{
				//view record form
				recreateForm: true,
				beforeShowForm: function(e){
					var form = $(e[0]);
					form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
				}
			}
		)
		.navButtonAdd(pager_selector,{
     	   caption:"添加", 
    	   id:"AddNews",
    	   buttonicon:"icon-plus-sign purple", 
    	   onClickButton: function(){ 
    			   self.location.href="<%=request.getContextPath()%>/admin/addnewsindex.do";
    	   }, 
    	   position:"first"
    	})
		
		function style_edit_form(form) {
			//enable datepicker on "sdate" field and switches for "stock" field
			form.find('input[name=sdate]').datepicker({format:'yyyy-mm-dd' , autoclose:true})
				.end().find('input[name=stock]')
					  .addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>');
	
			//update buttons classes
			var buttons = form.next().find('.EditButton .fm-button');
			buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
			buttons.eq(0).addClass('btn-primary').prepend('<i class="icon-ok"></i>');
			buttons.eq(1).prepend('<i class="icon-remove"></i>')
			
			buttons = form.next().find('.navButton a');
			buttons.find('.ui-icon').remove();
			buttons.eq(0).append('<i class="icon-chevron-left"></i>');
			buttons.eq(1).append('<i class="icon-chevron-right"></i>');		
		}
	
		function style_delete_form(form) {
			var buttons = form.next().find('.EditButton .fm-button');
			buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
			buttons.eq(0).addClass('btn-danger').prepend('<i class="icon-trash"></i>');
			buttons.eq(1).prepend('<i class="icon-remove"></i>');
		}
		
		function style_search_filters(form) {
			form.find('.delete-rule').val('X');
			form.find('.add-rule').addClass('btn btn-xs btn-primary');
			form.find('.add-group').addClass('btn btn-xs btn-success');
			form.find('.delete-group').addClass('btn btn-xs btn-danger');
		}
		function style_search_form(form) {
			var dialog = form.closest('.ui-jqdialog');
			var buttons = dialog.find('.EditTable')
			buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'icon-retweet');
			buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'icon-comment-alt');
			buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'icon-search');
		}
		
		function beforeDeleteCallback(e) {
			var form = $(e[0]);
			if(form.data('styled')) return false;
			
			form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
			style_delete_form(form);
			
			form.data('styled', true);
		}
		
		function afterSubmitCallback(e){
        	//var res=JSON.parse(e.responseText);
        	//console.log(e);
        	//return [res.success,res.message];
        	var res = {success:true,message:'OK'};
        	return [res.success, res.message];
        }

		
		function beforeEditCallback(e) {
			var form = $(e[0]);
			form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
			style_edit_form(form);
		}
	
	
	
		//it causes some flicker when reloading or navigating grid
		//it may be possible to have some custom formatter to do this as the grid is being created to prevent this
		//or go back to default browser checkbox styles for the grid
		function styleCheckbox(table) {
		/**
			$(table).find('input:checkbox').addClass('ace')
			.wrap('<label />')
			.after('<span class="lbl align-top" />')
	
	
			$('.ui-jqgrid-labels th[id*="_cb"]:first-child')
			.find('input.cbox[type=checkbox]').addClass('ace')
			.wrap('<label />').after('<span class="lbl align-top" />');
		*/
		}
		
	
		//unlike navButtons icons, action icons in rows seem to be hard-coded
		//you can change them like this in here if you want
		function updateActionIcons(table) {
			/**
			var replacement = 
			{
				'ui-icon-pencil' : 'icon-pencil blue',
				'ui-icon-trash' : 'icon-trash red',
				'ui-icon-disk' : 'icon-ok green',
				'ui-icon-cancel' : 'icon-remove red'
			};
			$(table).find('.ui-pg-div span.ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
			*/
		}
		
		//replace icons with FontAwesome icons like above
		function updatePagerIcons(table) {
			var replacement = 
			{
				'ui-icon-seek-first' : 'icon-double-angle-left bigger-140',
				'ui-icon-seek-prev' : 'icon-angle-left bigger-140',
				'ui-icon-seek-next' : 'icon-angle-right bigger-140',
				'ui-icon-seek-end' : 'icon-double-angle-right bigger-140'
			};
			$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
				var icon = $(this);
				var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
				
				if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
			})
		}
	
		function enableTooltips(table) {
			$('.navtable .ui-pg-button').tooltip({container:'body'});
			$(table).find('.ui-pg-div').tooltip({container:'body'});
		}
	
		//var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow');
	
	
	});

</script>
<script src="<%=request.getContextPath()%>/js/msgtest.js"></script>
</html>